<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../node_modules/axios/dist/axios.min.js"></script>
</head>
<body>
    <button>获取</button>
    <button>添加</button>
    <button>覆盖修改</button>
    <button>删除</button>
    <button>单独修改</button>
    <button>学员</button>

    <ul></ul>
    <script>
        let btn = document.querySelectorAll('button')
        let ul = document.querySelector('ul')

        axios.defaults.method = 'get';
        axios.defaults.baseURL = 'http://api.liu.com:3000'


        btn[0].addEventListener('click',async ()=>{
            let {data} = await axios('/movie')
            data.forEach(item => {
                let li = document.createElement('li')
                li.innerHTML=item.name;
                ul.appendChild(li)
            });
        })

        btn[1].addEventListener('click',()=>{
            axios.post('http://api.liu.com:3000/movie',{
                name:"流浪地球",
                director:"吴京",
                star:"吴京"
            })
        })

        btn[2].addEventListener('click',()=>{
            axios.put('http://api.liu.com:3000/movie/1',{
                name:"壮志凌云",
            })
        })


        btn[3].addEventListener('click',()=>{
            axios.delete('http://api.liu.com:3000/movie/2',{
                
            })
        })

        btn[4].addEventListener('click',()=>{
            axios.patch('http://api.liu.com:3000/movie/5',{
                name:"碟中谍",
                star:"汤姆克鲁斯"
            })
        })
        btn[5].addEventListener('click',async ()=>{
            let {data} = await axios('/students')
            data.forEach(item => {
                let li = document.createElement('li')
                li.innerHTML=item.name;
                ul.appendChild(li)
            });
        })
    </script>

</body>
</html>